const connectionPoll = require('../app/mysql')


class UserService{
    async create(user)
    {
        const { name, password } = user;
        const statement = 'insert into t_user(name,password) values(?,?)';
        let val = await connectionPoll.promise().execute(statement, [name, password]);
        return val;
    }

    async findName(name)
    {
        const statement = "select name from t_user where name=?";
        const [val] = await connectionPoll.promise().execute(statement, [name]);
        console.log("val:", val);
        return val;
    }

    async findPassword(name)
    {
        const statement = 'select password from t_user where name = ?';
        const [val] = await connectionPoll.promise().execute(statement, [name]);
        return val[0];
    }
}

module.exports = new UserService();